package top.zhangjianyong.blog.manage.controller;

import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import top.zhangjianyong.blog.params.ai.ChatParam;
import top.zhangjianyong.blog.response.ApiResponse;
import top.zhangjianyong.blog.service.AIService;

/**
 * @author zhangjianyong
 * @since 2025/7/7 12:03
 */
@RequestMapping("/ai")
@RestController
public class AIController {

  @Resource private AIService aiService;

  /**
   * 流式chat接口，前端可实时获取AI回复（POST方式，兼容fetch流式读取）
   *
   * @param param 用户输入内容
   * @return Flux<String> 流式AI回复
   */
  @PostMapping(value = "/chat", produces = "text/event-stream;charset=UTF-8")
  public Flux<String> chat(@RequestBody ChatParam param) {
    return aiService.chat(param);
  }

  @PostMapping("/chatWithStore")
  public Flux<String> chatWithStore(@RequestBody ChatParam param) {
    return aiService.chatWithStore(param);
  }

  @PostMapping("/buildBlogVectorStore")
  public ApiResponse buildBlogVectorStore() {
    return aiService.buildBlogVectorStore();
  }
}
